

naive_bayes_recp = recipe(diagnosis~.,data = train_data) |>
  step_smotenc(diagnosis,over_ratio=0.5 ,neighbors=1,seed=123)

base_prep = prep(naive_bayes_recp)
new_data = bake(base_prep,new_data=NULL)

naive_bayes_spec = naive_Bayes() |>
  set_engine("naivebayes") |>
  set_mode("classification")

naive_bayes_flow = workflow() |>
  add_recipe(naive_bayes_recp) |>
  add_model(naive_bayes_spec)


naive_bayes_fit = fit(naive_bayes_flow,data = train_data)
tryCatch(
  {
    naive_bayes_predict = augment(naive_bayes_fit,new_data=test_data)
  },error = function(e) {
    rlang::last_trace()
  }
)

bayes_auc = roc_auc(data = naive_bayes_predict,truth = diagnosis,.pred_1,event_level="second")
bayes_acc = accuracy(data = naive_bayes_predict,truth = diagnosis,.pred_class)
bayes_sens = sensitivity(data=naive_bayes_predict,truth = diagnosis,.pred_class,event_level = "second")
bayes_spec = specificity(data=naive_bayes_predict,truth = diagnosis,.pred_class,event_level = "second")
bayes_ppv = ppv(data=naive_bayes_predict,truth = diagnosis,.pred_class,event_level = "second")
bayes_conf_mat = conf_mat(data=naive_bayes_predict,truth = diagnosis,.pred_class)
bayes_f_meas = f_meas(data=naive_bayes_predict,truth = diagnosis,.pred_class,event_level = 'second')

# bayes_evaluation_table <- tibble(
#   metric = c("auc", "acc","sens","spec","ppv"),
#   value = c(auc$.estimate, acc$.estimate,sens$.estimate,spec$.estimate,ppv$.estimate)
# )
# 
# bayes_evaluation_table

# conf_mat

